package com.yf.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yf.domain.security.Menu;
import com.yf.model.query.MenuQueryObject;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * @author chentianwei
 * @date 2023/6/25 10:58
 * @description 菜单Dao
 */
@Mapper
public interface MenuMapper extends BaseMapper<Menu> {
    LinkedHashSet<Menu> findByRolesIdsAndTypeNot(@Param("roleIds") Set<Long> roleIds,
                                                 @Param("type") int type);

    Set<Menu> queryTopMenuTree(@Param("queryObject") MenuQueryObject menuQueryObject);

    List<Menu> findByPidIsNullOrderByMenuSort();

    List<Menu> findByPidOrderByMenuSort(@Param("pid") Long pid);

    @Select("SELECT menu_id id FROM sys_menu WHERE title = #{title}")
    Menu findByTitle(@Param("title") String title);

    @Select("SELECT menu_id id FROM sys_menu WHERE name = #{name}")
    Menu findByComponentName(@Param("name") String name);

    @Select("SELECT count(*) FROM sys_menu WHERE pid = #{pid}")
    int countByPid(@Param("pid") Long pid);

    @Select("update sys_menu set sub_count = #{count} where menu_id = #{menuId} ")
    void updateSubCntById(@Param("count") int count, @Param("menuId") Long menuId);

    Menu selectById(Long id);

    List<Menu> findAll(@Param("criteria") MenuQueryObject queryObject);

}
